#include "DashboardUI_AddRecord.h"
#include "ui_dashboard_addrecord.h"

#include "Authentication.h"

#include "RecordDatabase.h"

DashboardUI_AddRecord::DashboardUI_AddRecord(QWidget *parent) :
    QWidget(parent),
    validator(this),
    ui(new Ui::DashboardUI_AddRecord)
{
    ui->setupUi(this);

    // Set up field validator
    validator.addAllFields();
    validator.setButton(ui->submitButton);
}

DashboardUI_AddRecord::~DashboardUI_AddRecord()
{
    delete ui;
}

void DashboardUI_AddRecord::on_submitButton_clicked()
{
    Record record;
    record.bloodPressureDiastolic = ui->bloodPressureDiaField->text().toInt();
    record.bloodPressureSystolic = ui->bloodPressureSysField->text().toInt();
    record.comment = ui->commentField->toPlainText();
    record.pulseRate = ui->pulseField->text().toInt();
    record.temperature = ui->temperatureField->text().toFloat();
    record.observationDate = QDateTime::currentDateTime().toString();

    User *user = Authentication::getInstance()->getUser();

    if (user->getUserType() == User::PATIENT)
    {
        RecordDatabase recordDB;
        recordDB.addRecord(&record, user->getId());
    }
}
